import axios from "../utils/axios";
let uid, token;

// 登录
export const login = params => {
    return axios.post(`${ base }/center/public/loginmob`, params).then(res => {
        let data = res.data;
        if (data.data && data.data.token) {
            token = data.data.token;
            uid = data.data.uid;
            localStorage.token = token;
            // console.log("token:", token);
        }
        if (!data.errno) this.checkAppRegist();
        return Promise.resolve(data);
    });
};
// app登录,调用微信登录,QQ登录.
export const loginApp = params => {
    return axios.post(`${ base }/apix/7dtime/loginapp`, params).then(res => {
        let data = res.data;
        if (data.data && data.data.token) {
            token = data.data.token;
            uid = data.data.uid;
            localStorage.token = token;
            // console.log("token:", token);
        }
        if (!data.errno) this.checkAppRegist();
        return Promise.resolve(data);
    });
};

// 登录-手机验证码登录,可能未注册
export const loginCode = params => {
    return axios.post(`${ base }/center/public/logincode`, params).then(res => {
        let data = res.data;
        if (data.data && data.data.token) {
            token = data.data.token;
            uid = data.data.uid;
            localStorage.token = token;
            // console.log("token:", token);
        }
        if (!data.errno) this.checkAppRegist();
        return Promise.resolve(data);
    });
};
// 退出登录
export const logout = params => {
    return axios.post(`${ base }/center/public/logoutmob`, params).then(res => {
        token = "";
        uid = 0;
        return Promise.resolve(res.data);
    });
};